package org.jeecg.modules.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.system.entity.BizEquipmentEntity;

import java.util.List;
import java.util.Map;

public interface BizEquipmentMapper extends BaseMapper<BizEquipmentEntity> {

    @Select("<script> " +
            "select status,count(1) count from biz_equipment_state " +
            "where eq_id in (select eq_id from biz_equipment a where a.status=1 <when test='siteId !=null'> and a.site_id = #{siteId} </when> ) group by status " +
            "</script>")
    List<Map<?,?>> getStatusCount(String siteId);

    @Select("<script>select a.*,b.status onlineStatus from biz_equipment a left join biz_equipment_state b on a.eq_id=b.eq_id " +
            "where 1=1 <when test='siteId !=null'> and a.site_id = #{siteId} </when> and a.site_id in (select site_id from biz_site_user where user_id=#{userId}) " +
            " <when test='eqId !=null'> and a.eq_id = #{eqId} </when> " +
            "order by create_time asc</script>")
    List<BizEquipmentEntity> getEqWithOnlineNormal(String siteId,String eqId,String userId);

    @Select("<script>select a.*,b.status onlineStatus from biz_equipment a left join biz_equipment_state b on a.eq_id=b.eq_id " +
            "where 1=1 <when test='siteId !=null'> and a.site_id = #{siteId} </when>  " +
            " <when test='eqId !=null'> and a.eq_id = #{eqId} </when> " +
            "order by create_time asc</script>")
    List<BizEquipmentEntity> getEqWithOnlineAdmin(String siteId,String eqId);
}
